enyo.kind({
    name: "MyApps.ProductsList",
    kind: enyo.VFlexBox,
    events: {
        onBack: "",
    },
    components: [    /**
     * service
     */
    {
        name: "getData",
        kind: "WebService",
        url: "http://query.yahooapis.com/v1/public/yql?q=select * from xml where url= 'http://www.golfplus.fr/xml/xml_iphone_BA.xml' &format=json&callback=",
        onSuccess: "gotData",
        onFailure: "gotDataFailure"
    },    /**
     * Layout
     */
    {
        name: "pane",
        kind: "Pane",
        flex: 1,
        transitionKind: "enyo.transitions.LeftRightFlyin",
        components: [{
            kind: "VFlexBox",
            
            components: [{
            
                kind: "PageHeader",
                className: "enyo-header-dark",
                components: [{
                    kind: "IconButton",
                    onclick: "doBack",
                    icon: "images/menu-icon-back.png",
                    className: "enyo-button-dark"
                }, {
                    kind: "VFlexBox",
                    flex: 1,
                    align: "center",
                    components: [{
                        content: "Les bonnes affaires"
                    }, ]
                }, ]
            }, {
                kind: "Scroller",
                flex: 1,
                className: "list",
                components: [{
                    name: "list",
                    kind: "VirtualRepeater",
                    flex: 1,
                    onSetupRow: "listSetupRow",
                    components: [{
                        kind: "Item",
                        layoutKind: "VFlexLayout",
                        components: [{
                            kind: "HFlexBox",
                            components: [{
                                name: "photowrapper",
                                className: "productphotowrapper",
                                flex: 1,
                                components: [{
                                    name: "photo",
                                    kind: "Image",
                                    className: "productphoto",
                                
                                }, ]
                            }, {
                                kind: "VFlexBox",
                                flex: 2,
                                components: [{
                                    name: "name",
                                    className: "productname",
                                }, {
                                    name: "resume",
                                    className: "productresume",
                                }, {
                                    name: "price",
                                    className: "productprice",
                                }, ]
                            }, ]
                        }, ],
                        onclick: "listItemClick"
                    }]
                }, ]
            }, ]
        
        }, {
            name: "productDetail",
            kind: "MyApps.ProductDetail",
            onBack: "goBack",
            lazy: true,
        }],
    }],
    
    
    create: function(){
        this.inherited(arguments);
        this.data = [];
        this.$.getData.call();
    },
    gotData: function(inSender, inResponse){
        this.data = inResponse.query.results.catalogue.references;
        this.data.sort(this.orderByGolfClub);
        this.$.pane.render();
    },
    gotDataFailure: function(inSender, inResponse){
        console.log("got failure from getData");
    },
    listSetupRow: function(inSender, inRow){
        var f = this.data[inRow];
        if (f) {
            this.$.photo.setSrc(f.url_image_petite)
            this.$.name.setContent(f.libelle.replace(/\\\"/g, "\""));
            this.$.resume.setContent(f.resume.replace(/&euro/g, "€"));
            this.$.price.setContent(f.prix_standard + " €");
            return true;
        }
    },
    
    listItemClick: function(inSender, inEvent){
        var product = this.data[inEvent.rowIndex];
        this.$.pane.selectViewByName("productDetail");
        this.$.productDetail.setData(product);
        
    },
    
    
    goBack: function(inSender, inEvent){
        this.$.pane.back(inEvent);
    },


});



